package com.sjp.demo.rpc.client;

import java.lang.reflect.Proxy;

public class RpcProxyClient {

    private String host;
    private int port;

    public static RpcProxyClient getInstance(String host, int port) {
        return new RpcProxyClient(host, port);
    }

    private RpcProxyClient(String host, int port) {
        this.host = host;
        this.port = port;
    }

    public <T> T getService(final Class<T> interfaceClass){
        return (T)Proxy.newProxyInstance(interfaceClass.getClassLoader(),
                new Class[]{interfaceClass}, new RemoteInvocationHandler(host, port));
    }
}
